<?php 
session_start();
if (isset($_SESSION['uid'])){
    $uid=$_SESSION['uid'];
}else{
    echo 'uid error';
    exit;
}
include './c/config.php';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}
$sql="SELECT * FROM `app_student` where id='".$uid."' limit 0,1 "; 
$query=$mysqli->query($sql);
if($query->num_rows>0){
    $userInfo=array();
    while ($list=$query->fetch_assoc()){
        $userInfo=$list;
    }
}else{
    exit;
}

$tmeShiJian=explode(':', $userInfo['shijian']);
if($tmeShiJian[0] < 12){
//$theshijian="上午";
}else{
//$theshijian="下午";
}
$theshijian=$userInfo['shijian'];
 
//header('Content-type: image/jpeg');
$title='2023上海市中学生现代文阅读素养活动';
$image = new Imagick('./img/print.jpg');
$color = new ImagickPixel('#000000');
$draw = new ImagickDraw();
$draw->settextkerning(2);
$draw->setFont('msyh.ttf');
$draw->setFontSize(40);
$draw->setFillColor($color);
$draw->setTextAntialias(true);
$draw->annotation(370, 1439, $userInfo['name']);
$draw->annotation(1374, 1439, $userInfo['school']);
$draw->annotation(370, 1548, $userInfo['nianji']);
$draw->annotation(1380, 1548, $userInfo['idcard']);
$draw->annotation(370, 1648, $userInfo['kc']);

$draw->setFontSize(37);
$draw->annotation(1368, 1648, '2024年1月6日（周六）上午9:30-11:00');
$draw->setFontSize(40);

$draw->annotation(370, 1752, '上海市商业学校');
$draw->setFontSize(36);
$draw->annotation(1370, 1754, '静安区共和新路1458号');
$draw->annotation(370, 1856, '地铁一号线延长路站，46，95，40，518');
$colorTwo = new ImagickPixel('#ae1f25');
$draw->setFontSize(48);
$draw->setFontWeight(800);
$draw->setFillColor($colorTwo);
$draw->annotation(400, 1356, $userInfo['hao']);


//$draw->setFontSize(58);
//$draw->setFontWeight(900);
//$draw->setFillColor($colorTwo);
//$draw->annotation(130, 1280, $title);

$image->drawimage($draw);
file_put_contents('./pic/'.$uid.'.jpg', $image);

echo  json_encode(array('status'=>'ok'));
?>